﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LIMS.Web
{
    public partial class AdmNoticeManage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                AspNetPager1.RecordCount = BLL.NewsInfoManager.TotalCount();
                rpNewsInfo.DataSource = Common.CommonPager<Model.NewsInfos>.GetTSourceByPager(BLL.NewsInfoManager.GetAllNews(), AspNetPager1.PageSize, 1);
                rpNewsInfo.DataBind();
            }
        }

        protected String ConventNewsTypeToString(Object objNewsType)
        {
            return (objNewsType == null || objNewsType.ToString() == null) ? "普通" : (Boolean.Parse(objNewsType.ToString()) == true ? "紧急" : "普通");
        }
        /// <summary>
        /// 字符串截取
        /// </summary>
        /// <param name="strInput">需要截断的字符串</param>
        /// <param name="nLength">截断字符串的长度</param>
        /// <returns></returns>
        protected string SubString(string strInput, int nLength)
        {
            if (strInput.Length <= nLength)
            {
                return strInput;
            }
            return strInput.Substring(0, nLength) + "…";
        }

        protected void ddlInfo_SelectedIndexChanged(object sender, EventArgs e)
        {
            rpNewsInfo.DataSource = Common.CommonPager<Model.NewsInfos>.GetTSourceByPager(BLL.NewsInfoManager.GetNewsByType(ddlInfo.SelectedValue), AspNetPager1.PageSize, 1);
            rpNewsInfo.DataBind();
        }

        protected void btnFind_Click(object sender, EventArgs e)
        {
            rpNewsInfo.DataSource = Common.CommonPager<Model.NewsInfos>.GetTSourceByPager(BLL.NewsInfoManager.SearchByTitle(txtCaption.Text.Trim()), AspNetPager1.PageSize, 1);
            rpNewsInfo.DataBind();
        }

        protected void btnAddNotice_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/AdmIsuueNotice.aspx");
        }

        protected void rpNewsInfo_OnItemDataBound(object sender, RepeaterItemEventArgs e)
        {

        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            if (ddlInfo.SelectedValue == "-1")
            {
                rpNewsInfo.DataSource = Common.CommonPager<Model.NewsInfos>.GetTSourceByPager(BLL.NewsInfoManager.GetAllNews(), AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex);
                rpNewsInfo.DataBind();
            }
            else
            {
                rpNewsInfo.DataSource = Common.CommonPager<Model.NewsInfos>.GetTSourceByPager(BLL.NewsInfoManager.GetNewsByType(ddlInfo.SelectedValue), AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex);
                rpNewsInfo.DataBind();
            }
        }


    }
}